#!/usr/bin/python3
import tkinter as tk
import tkinter.ttk as ttk
from threading import Thread


class PimeSetting:
    def __init__(self, master=None):
        # build ui
        toplevel3 = tk.Tk() if master is None else tk.Toplevel(master)
        toplevel3.configure(height=360, width=640)
        notebook11 = ttk.Notebook(toplevel3)
        notebook11.configure(height=290, width=640)
        frame10 = tk.Frame(notebook11)
        frame10.configure(height=200, padx=4, pady=4, width=200)
        label1 = tk.Label(frame10)
        label1.configure(text='中/英文:')
        label1.place(anchor="nw", x=8, y=8)
        radiobutton1 = tk.Radiobutton(frame10)
        self.cnEn = tk.StringVar(value='cn')
        radiobutton1.configure(text='中文', value="cn", variable=self.cnEn)
        radiobutton1.place(anchor="nw", x=100, y=8)
        radiobutton2 = tk.Radiobutton(frame10)
        radiobutton2.configure(text='英文', value="en", variable=self.cnEn)
        radiobutton2.place(anchor="nw", x=200, y=8)
        label2 = tk.Label(frame10)
        label2.configure(text='全/半角:')
        label2.place(anchor="nw", x=8, y=36)
        radiobutton3 = tk.Radiobutton(frame10)
        self.fullHalf = tk.StringVar(value='full')
        radiobutton3.configure(text='全角', value="full", variable=self.fullHalf)
        radiobutton3.place(anchor="nw", x=100, y=36)
        radiobutton4 = tk.Radiobutton(frame10)
        radiobutton4.configure(text='半角', value="half", variable=self.fullHalf)
        radiobutton4.place(anchor="nw", x=200, y=36)
        frame10.pack(side="top")
        notebook11.add(frame10, text='通用')
        frame11 = tk.Frame(notebook11)
        frame11.configure(height=200, width=200)
        label18 = tk.Label(frame11)
        label18.configure(text='候选个数:')
        label18.grid(column=0, padx=4, pady=4, row=0)
        labeledscale1 = ttk.LabeledScale(frame11, from_=1, to=9)
        labeledscale1.grid(column=1, padx=4, pady=4, row=0)
        label21 = tk.Label(frame11)
        label21.configure(text='每行显示:')
        label21.grid(column=0, row=1)
        combobox5 = ttk.Combobox(frame11)
        combobox5.grid(column=1, padx=4, pady=4, row=1)
        frame11.pack(side="top")
        notebook11.add(frame11, compound="left", text='外观')
        frame12 = tk.Frame(notebook11)
        frame12.configure(height=200, width=200)
        label16 = tk.Label(frame12)
        label16.configure(text='中/英文:')
        label16.place(anchor="nw", x=0, y=0)
        frame12.pack(side="top")
        notebook11.add(frame12, compound="left", text='词库')
        frame13 = tk.Frame(notebook11)
        frame13.configure(height=200, width=200)
        label17 = tk.Label(frame13)
        label17.configure(text='中/英文:')
        label17.place(anchor="nw", x=0, y=0)
        frame13.pack(side="top")
        notebook11.add(frame13, compound="left", text='高级')
        notebook11.place(anchor="nw", x=0, y=0)
        button4 = ttk.Button(toplevel3)
        button4.configure(text='确定')
        button4.place(anchor="sw", relx=0.0, rely=0.0, x=420, y=350)
        button5 = ttk.Button(toplevel3)
        button5.configure(text='取消')
        button5.place(anchor="sw", relx=0.0, rely=0.0, x=520, y=350)
        toplevel3.bind("<FocusIn>", self.callback, add="")
        toplevel3.attributes('-topmost', True)
        # Main widget
        self.mainwindow = toplevel3

    def run(self):
        self.mainwindow.mainloop()

    def callback(self, event=None):
        print('callback works!')
        self.mainwindow.attributes('-topmost', False)


def startup():
    t = Thread(target=_start)
    t.start()


def _start():
    PimeSetting().run()


if __name__ == "__main__":
    startup()
